<template>
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header>
      <div>
        <img src="../assets/img/mgmtLogo.jpg" alt="" style="width:50px;height:50px;border-radius:50%;transform: rotate(90deg);">
        <span>老马雕刻后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 主体 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollpase ? '64px' :'200px'">
        <div class="toggle-button" @click="toggleCollpase">
          |||
        </div>
         <el-menu background-color="#333744" text-color="#fff" active-text-color="#4091ff" unique-opened :collapse="isCollpase" 
         :collapse-transition="false" router default-active="activePath">
          <el-submenu :index="item.id" v-for="item in menuList" :key="item.id" >
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="savenavState(subItem.path)">
              <template slot="title">
              <i :class="iconsObj[subItem.id]"></i>
              <span>{{subItem.authName}}</span>
            </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体内容 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>

  </el-container>
</template>

<script>
  export default {
    methods : {
      logout(){
        window.sessionStorage.clear();
        this.$router.push("/login")
      },
      //菜单的展开收起
      toggleCollpase (){
        this.isCollpase = !this.isCollpase
      },
      savenavState (activePath){
        window.sessionStorage.setItem("activePath","/"+activePath);
        this.activePath = "/"+activePath
      }
    },
    created (){
      this.activePath = window.sessionStorage.getItem("activePath")
    },
    data (){
      return{
        menuList : [
          {
            'authName' : '用户管理',
            'id' : '001',
            'path' : 'users',
            'children' :[
              {
                'authName' : '商品管理',
                'id' : '011',
                'path' : 'product',
              },
              {
                'authName' : '数据统计',
                'id' : '012',
                'path' : 'dataStatistics',
              }
            ]
          },
          {
            'authName' : '管理员管理',
            'id' : '002',
            'path' : 'usersadmin',
            'children' :[
              {
                'authName' : '总商品管理',
                'id' : '021',
                'path' : 'totalProduct',
              },
              {
                'authName' : '总数据统计',
                'id' : '022',
                'path' : 'totalDataStatistics',
              }
            ]
          }  
        ],
        iconsObj : {
          '001' : 'el-icon-user-solid',
          '011' : 'el-icon-notebook-1',
          '012' : 'el-icon-shopping-cart-1',
          '002' : 'el-icon-user',
          '021' : 'el-icon-notebook-2',
          '022' : 'el-icon-shopping-cart-2',
        },
        isCollpase : false,
        activePath : ""
      }
    }
  }
</script>

<style lang="less" scoped>
  .el-header{
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: #fff;
    font-size: 20px;
    >div{
      display: flex;
      align-items: center;
      >span{
        margin-left: 15px;
      }
    }
  }
  .el-aside{
    background-color: #333744;
    .el-menu{
      border-right:none;
    }
  }
  .el-main{
    background-color: #eaedf1;
  }
  .home-container{
    height: 100%;
  }
  .toggle-button{
    background-color: #4a5064;
    color:#fff;
    font-size:10px;
    line-height: 24px;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
  .el-breadcrumb{
    height:24px;
     line-height: 30px;
  }
</style>
